package sanshi.contect.observer.v9;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 这个事件源是：button
 * 事件为：按下
 * 观察者是：Listener
 */
public class TestFrame extends Frame{
    public void launch(){
        Button button = new Button("press me");
        button.addActionListener(new MyActionListener());
        button.addActionListener(new MyActionListener2());
        this.add(button);
        this.pack();

        this.setLocation(400,400);
        this.setVisible(true);
    }

    public static void main(String[] args) {
        new TestFrame().launch();
    }

    public class MyActionListener implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("button press 1 ");
        }
    }

    public class MyActionListener2 implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println(e.getSource());
            System.out.println("button press 2 ");
        }
    }
}
